from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-01 14:02:19.337204
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 01, Jul, 2022
Time: 14:02:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6561
Nobs: 704.000 HQIC: -50.0135
Log likelihood: 8783.62 FPE: 1.51924e-22
AIC: -50.2387 Det(Omega_mle): 1.33813e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298924 0.057619 5.188 0.000
L1.Burgenland 0.107101 0.037872 2.828 0.005
L1.Kärnten -0.109542 0.020051 -5.463 0.000
L1.Niederösterreich 0.210801 0.079094 2.665 0.008
L1.Oberösterreich 0.106251 0.077496 1.371 0.170
L1.Salzburg 0.256904 0.040484 6.346 0.000
L1.Steiermark 0.045119 0.052746 0.855 0.392
L1.Tirol 0.109409 0.042819 2.555 0.011
L1.Vorarlberg -0.058659 0.037145 -1.579 0.114
L1.Wien 0.039090 0.068536 0.570 0.568
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048946 0.120779 0.405 0.685
L1.Burgenland -0.033967 0.079385 -0.428 0.669
L1.Kärnten 0.041120 0.042030 0.978 0.328
L1.Niederösterreich -0.168257 0.165795 -1.015 0.310
L1.Oberösterreich 0.424653 0.162445 2.614 0.009
L1.Salzburg 0.288554 0.084861 3.400 0.001
L1.Steiermark 0.100748 0.110566 0.911 0.362
L1.Tirol 0.319129 0.089757 3.555 0.000
L1.Vorarlberg 0.027981 0.077863 0.359 0.719
L1.Wien -0.041479 0.143664 -0.289 0.773
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187454 0.029500 6.354 0.000
L1.Burgenland 0.090069 0.019390 4.645 0.000
L1.Kärnten -0.008011 0.010266 -0.780 0.435
L1.Niederösterreich 0.264954 0.040495 6.543 0.000
L1.Oberösterreich 0.138438 0.039676 3.489 0.000
L1.Salzburg 0.045956 0.020727 2.217 0.027
L1.Steiermark 0.019743 0.027005 0.731 0.465
L1.Tirol 0.091509 0.021923 4.174 0.000
L1.Vorarlberg 0.056927 0.019018 2.993 0.003
L1.Wien 0.114237 0.035089 3.256 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111734 0.029996 3.725 0.000
L1.Burgenland 0.045679 0.019715 2.317 0.021
L1.Kärnten -0.013780 0.010438 -1.320 0.187
L1.Niederösterreich 0.192711 0.041175 4.680 0.000
L1.Oberösterreich 0.301599 0.040343 7.476 0.000
L1.Salzburg 0.108217 0.021075 5.135 0.000
L1.Steiermark 0.104904 0.027459 3.820 0.000
L1.Tirol 0.103848 0.022291 4.659 0.000
L1.Vorarlberg 0.067445 0.019337 3.488 0.000
L1.Wien -0.023087 0.035679 -0.647 0.518
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.135273 0.054755 2.471 0.013
L1.Burgenland -0.051784 0.035989 -1.439 0.150
L1.Kärnten -0.044338 0.019054 -2.327 0.020
L1.Niederösterreich 0.156614 0.075163 2.084 0.037
L1.Oberösterreich 0.140232 0.073644 1.904 0.057
L1.Salzburg 0.286812 0.038471 7.455 0.000
L1.Steiermark 0.047771 0.050125 0.953 0.341
L1.Tirol 0.166884 0.040691 4.101 0.000
L1.Vorarlberg 0.093166 0.035299 2.639 0.008
L1.Wien 0.071662 0.065129 1.100 0.271
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055185 0.043531 1.268 0.205
L1.Burgenland 0.037640 0.028612 1.316 0.188
L1.Kärnten 0.051111 0.015148 3.374 0.001
L1.Niederösterreich 0.217273 0.059756 3.636 0.000
L1.Oberösterreich 0.295035 0.058548 5.039 0.000
L1.Salzburg 0.047895 0.030586 1.566 0.117
L1.Steiermark 0.001762 0.039850 0.044 0.965
L1.Tirol 0.140570 0.032350 4.345 0.000
L1.Vorarlberg 0.073902 0.028064 2.633 0.008
L1.Wien 0.080515 0.051779 1.555 0.120
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175591 0.052065 3.373 0.001
L1.Burgenland -0.002361 0.034221 -0.069 0.945
L1.Kärnten -0.063029 0.018118 -3.479 0.001
L1.Niederösterreich -0.081207 0.071471 -1.136 0.256
L1.Oberösterreich 0.195012 0.070026 2.785 0.005
L1.Salzburg 0.056470 0.036582 1.544 0.123
L1.Steiermark 0.236162 0.047662 4.955 0.000
L1.Tirol 0.497616 0.038692 12.861 0.000
L1.Vorarlberg 0.045036 0.033565 1.342 0.180
L1.Wien -0.056754 0.061930 -0.916 0.359
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170149 0.059191 2.875 0.004
L1.Burgenland -0.012742 0.038905 -0.328 0.743
L1.Kärnten 0.063874 0.020598 3.101 0.002
L1.Niederösterreich 0.207314 0.081253 2.551 0.011
L1.Oberösterreich -0.078069 0.079611 -0.981 0.327
L1.Salzburg 0.213323 0.041589 5.129 0.000
L1.Steiermark 0.126390 0.054186 2.333 0.020
L1.Tirol 0.067146 0.043988 1.526 0.127
L1.Vorarlberg 0.119214 0.038159 3.124 0.002
L1.Wien 0.125780 0.070407 1.786 0.074
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363108 0.034298 10.587 0.000
L1.Burgenland 0.007419 0.022543 0.329 0.742
L1.Kärnten -0.023690 0.011935 -1.985 0.047
L1.Niederösterreich 0.215374 0.047081 4.575 0.000
L1.Oberösterreich 0.206121 0.046129 4.468 0.000
L1.Salzburg 0.043349 0.024098 1.799 0.072
L1.Steiermark -0.014970 0.031397 -0.477 0.634
L1.Tirol 0.105888 0.025488 4.154 0.000
L1.Vorarlberg 0.069524 0.022111 3.144 0.002
L1.Wien 0.030256 0.040796 0.742 0.458
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037415 0.138442 0.193650 0.155607 0.115071 0.101929 0.058216 0.218279
Kärnten 0.037415 1.000000 -0.015406 0.134295 0.055756 0.095254 0.435650 -0.053134 0.093393
Niederösterreich 0.138442 -0.015406 1.000000 0.335287 0.141614 0.294402 0.092529 0.176799 0.312294
Oberösterreich 0.193650 0.134295 0.335287 1.000000 0.226626 0.324939 0.176024 0.164261 0.264962
Salzburg 0.155607 0.055756 0.141614 0.226626 1.000000 0.137993 0.116581 0.139075 0.130038
Steiermark 0.115071 0.095254 0.294402 0.324939 0.137993 1.000000 0.145641 0.129432 0.073314
Tirol 0.101929 0.435650 0.092529 0.176024 0.116581 0.145641 1.000000 0.112906 0.141934
Vorarlberg 0.058216 -0.053134 0.176799 0.164261 0.139075 0.129432 0.112906 1.000000 0.004919
Wien 0.218279 0.093393 0.312294 0.264962 0.130038 0.073314 0.141934 0.004919 1.000000